﻿using BaseUI;
using BLL;
using System;
using System.Data;

namespace Thksoft.UserCotrols.JXKH
{
    public partial class MyIndexEx : BasePage
    {
        private Lc_TransactionBLL ltb = new Lc_TransactionBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Bind();
        }

        private string GetDate(string date)
        {
            string t = "";
            try
            {
                DateTime time = Convert.ToDateTime(date.ToString());

                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            catch
            {
                DateTime time = DateTime.Now;
                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            return t;
        }

        private void Bind()
        {
            string InerHtmls = " <div ><ul>";
            //查询待办信息
            DataTable temp = ltb.GetAgentDataAll(lognUser);
            if (temp != null)
            {
                Label1.Text = temp.Rows.Count.ToString();
            }

            #region 业务

            if (temp != null && temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    string stateDue = "";

                    string str = "【" + temp.Rows[i]["process"].ToString() + "】'" + temp.Rows[i]["business"].ToString() + "' " + temp.Rows[i]["nodename"].ToString() + "待处理" + stateDue;

                    str = SubStr(str);
                    InerHtmls += "<li><span>" + GetDate(temp.Rows[i]["d_transaction_time_begin"].ToString()).ToString() + "</span><a href='BusinessExpansion/Business/BussTran.aspx?trancId=" + temp.Rows[i]["tranid"].ToString() + "&BusinessId=" + temp.Rows[i]["bid"].ToString() + "'>" + str + "";

                    DateTime time = DateTime.Parse(temp.Rows[i]["d_transaction_time_begin"].ToString()).AddDays(10);//10天以内的有图标
                    DateTime now = DateTime.Now;
                    if (time >= now)
                    {
                        InerHtmls += "<img src='../Images/main_right/new.gif'/> ";
                    }
                    InerHtmls += "</a></li>";
                }
            }

            #endregion 业务

            InerHtmls += "</ul></div> ";
            div1.InnerHtml = InerHtmls;
        }

        /// <summary>
        /// 截取前30字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string SubStr(string str)
        {
            if (str.Length > 30)
            {
                str = str.Substring(0, 30) + "...";
            }
            return str;
        }
    }
}